package com.akuhome.resource.controller;

import com.akuhome.resource.dto.BuildInfo;
import com.akuhome.resource.entity.Build;
import com.akuhome.resource.service.CommonService;
import com.akuhome.resource.service.entity.BuildService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/build")
public class BuildController {
    @Autowired
    BuildService buildService;
    @Autowired
    CommonService commonService;

    @GetMapping
    public Object findAllBuild(){
        return buildService.findAllBuild();
    }

    @PostMapping
    public Object insertBuild(@Validated @RequestBody Build build, BindingResult bindingResult){
        return buildService.insertBuild(build);
    }
    @PutMapping
    public Object updateBuild(@Validated @RequestBody Build build, BindingResult bindingResult){
        return buildService.updateBuild(build);
    }
    @DeleteMapping("/{buildId}")
    public Object deleteBuild(@PathVariable Integer buildId){
        return buildService.deleteBuild(buildId);
    }

    @GetMapping("/roomtype")
    public Object getRoomType(){
        return commonService.findAllRoomType();
    }

    @GetMapping("/roomway")
    public Object getRoomWay(){
        return commonService.findAllRoomWay();
    }

    @GetMapping("/info")
    public Object findAllBuildInfo(){
        return buildService.findAllBuildInfo();
    }

    @PostMapping("/info")
    public Object insertBuildInfo(@Validated @RequestBody BuildInfo build, BindingResult bindingResult){
        buildService.insertBuildInfo(build);
        return null;
    }
    @PutMapping("/info")
    public Object updateBuildInfo(@Validated @RequestBody BuildInfo build, BindingResult bindingResult){
        buildService.updateBuildInfo(build);
        return null;
    }
    @DeleteMapping("/info/{buildId}")
    public Object deleteBuildInfo(@PathVariable Integer buildId){
        buildService.deleteBuildInfo(buildId);
        return null;
    }

}
